//
//  XiangQingViewController.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/7/7.
//  Copyright © 2016年 XuDong Jin. All rights reserved.
//

#import "XiangQingViewController.h"
#import "BuyCllowerViewController.h"
#import "IWTextView.h"
#import "WeiXinPayManager.h"
#import "IntroViewController.h"
#import "YXScrollowActionSheet.h"
#import "UIImage+MJ.h"
#import "BuySuccViewController.h"
#import "UIImage+Gif.h"
#import "NotFindDeviceView.h"
#import "IGMyiGalleryVC.h"
#import "PhotoEditVC.h"
#import "XQPhotoCell.h"
#import "ImageZoomView.h"
#import "AddWordVC.h"
#import "IGWorkDetailApi.h"
#import "UpOpenViewController.h"
#import "IGSearchVC.h"
#import "ArtGalleryCell_third.h"
#import "IGiGalleryListApi.h"
#import "IGiGalleryEqu.h"
#import "IGiGalleryPushApi.h"
#import "IGPushiGalleryListVC.h"
#import "IGAddOrderApi.h"
#import "OrderXQViewController.h"
#import "MyOrdersViewController.h"
#import "IGEmptyView.h"
#import "YHBrowserImageView.h"
#import "IGNetReachable.h"
#import "MyAltasViewController.h"//图册列表
#import "SDPhotoBrowser.h"
#import "GoodsDetailVC.h"//商品详情
#import "IGPaintingDetailOperateCell.h"//喜爱、添加画单、评论CELL
#import "IGWorkDetailFavoriteApi.h"
#import "IGWorkDetailCancelFavoriteApi.h"
#import "IGCommentVC.h"
#import "IGMainSearchApi.h"
#import "IGWorkDetailRecApi.h"
#import "IGAddToDrawVC.h"


/*
 遗留问题
 2.点击作者名字的跳转（用户体系为完成）
 3.点击评论界面，需要评论页给传递个block，里面是最新的评论数(等待)   (传递过去的model和接受的model不是相同的model)
 */

static NSString * const kCommentCellTableViewCellIdentifier = @"kCommentCellTableViewCellIdentifier";

@interface XiangQingViewController () <UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UITextViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate,SDPhotoBrowserDelegate>
{
    CGFloat contextHeight;
    CGFloat inset;
    
    CGRect selRect;
    CGFloat currtOff;
    BOOL isTop;
    UIImage * _shareImage;
    UIButton *push;
    NotFindDeviceView *findView;
}

@property (strong, nonatomic) UITableView *table;
@property (nonatomic, strong) IGWorkDetailApi *api;
@property (nonatomic, strong) IGWorkDetailModel *model;
@property (nonatomic, strong) NSArray *iGalleryListArr;
@property (nonatomic, strong) IGiGalleryListApi *igalleryListApi;
@property (nonatomic, strong) IGWorkDetailFavoriteApi *favoriteApi;//喜爱API
@property (nonatomic, strong) IGWorkDetailCancelFavoriteApi *cancelFavoriteApi;//取消喜爱API
@property (nonatomic, strong) IGMainSearchApi *searchApi;//搜索API
@property (nonatomic, strong) IGWorkDetailRecApi *recommedApi;//推荐API
@property (nonatomic, strong) NSArray *recListArray; //推荐画作列表


@end

@implementation XiangQingViewController



#pragma mark - lifeCycle
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (_isRoot)
    {
        _isRoot = !_isRoot;
    }
    else
    {
        [self loadData];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self ctreatTableView];
    [self loadData];
}

- (void)creatNav
{
    self.title = _model.worksName;
    [self ig_setupRightButtonItemWithTitle:nil image:[UIImage imageNamed:@"community_rightBar"] highLightedImage:[UIImage imageNamed:@"community_rightBar"]];
}

- (void)ctreatTableView
{
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, KSCREENWIDTH, KSCREENHEIGHT - 64 - 44) style:UITableViewStylePlain];
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>= 11.0)
    {
        self.table.estimatedRowHeight = 0;
        self.table.estimatedSectionHeaderHeight = 0;
        self.table.estimatedSectionFooterHeight = 0;
    }
    self.table.backgroundColor = [UIColor c2Color];
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.emptyDataSetDelegate = self;
    self.table.emptyDataSetSource = self;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.table registerClass:[XQPhotoCell class] forCellReuseIdentifier:@"XQPhotoCell"];
    [self.view addSubview:_table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-44);
        make.top.mas_equalTo(0);
    }];
    
    push = [UIButton buttonWithType:UIButtonTypeCustom];
    push.backgroundColor = [UIColor c8Color];
    //    [push setTitle:@"推送到画屏" forState:UIControlStateNormal];
    [push setTitle:NSLocalizedString(@"Push to iGallery", nil) forState:UIControlStateNormal];
    [push setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [push addTarget:self action:@selector(pushPhoto:) forControlEvents:UIControlEventTouchUpInside];
    push.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.view addSubview:push];
    [push mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    
    @KWeakObj(self)
    [self.table ig_setHeaderWithRefreshingBlock:^{
        [selfWeak loadData];
    }];
}

- (void)loadData
{
    if (![IGNetReachable isReachable]) {
        [self.table ig_endHeaderRefreshing];
        return;
    }
    self.api = [IGWorkDetailApi new];
    self.model = [IGWorkDetailModel new];
    self.api.worksId = self.p_id;
    __weak typeof(self) weakSelf = self;
    [self.api startWithDecodeClass:[IGWorkDetailResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [weakSelf.table ig_endHeaderRefreshing];
        if (responseObject)
        {
            IGWorkDetailResp *resp = responseObject;
            weakSelf.model = resp.data;
            [weakSelf loadRecommedData];
            [weakSelf creatNav];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.table reloadData];
            });
        } else {
            NSLog(@"222");
        }
    }];
}

-(void)loadRecommedData{
    self.recommedApi = [[IGWorkDetailRecApi alloc]init];
    self.recommedApi.pid = self.p_id;
    __weak typeof(self) weakSelf = self;
    [self.recommedApi startWithDecodeClass:[IGWorkDetailRecResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            IGWorkDetailRecResp *response = responseObject;
            IGWorkDetailRecModel *model = response.data;
            weakSelf.recListArray = [NSArray arrayWithArray:model.productList];
            [weakSelf.table reloadSections:[NSIndexSet indexSetWithIndex:5] withRowAnimation:UITableViewRowAnimationNone];
        }
    }];
}

- (void)showAlertViewWithTag:(NSInteger)i
{
    UIAlertController *alertVC;
    //重新编辑
    if (i == 100)
    {
        alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Sorry, your works doesn't pass the examination.", nil) message:[NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Reason",nil),_model.reason] preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:NSLocalizedString(@"Reedit", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UpOpenViewController *vc = [[UpOpenViewController alloc] initWithNibName:@"UpOpenViewController" bundle:nil];
            XQPhotoCell *cell = [self.table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
            vc.image = cell.imageV.image;
            vc.isOpen = YES;
            vc.isH = [_model.worksPlates isEqualToString:@"1"] ? YES : NO;
            vc.model = _model;
            [UIViewController ig_pushViewController:vc animated:YES];
        }];
        
        [alertVC addAction:action1];
        [alertVC addAction:action2];
    }
    else if (i == 101)
    {
        alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle: NSLocalizedString(@"Add to My Album", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            if (_model.ifCollected.integerValue == 1 || [[IGUser getUid] isEqualToString:_model.worksArtistId])
            if ( [[IGUser getUid] isEqualToString:_model.worksArtistId])
            {
                IGAddToDrawVC *addVc=[[IGAddToDrawVC alloc]init];
                addVc.workIds=@[_model.worksId];
                addVc.isSecrecy=_model.worksSecrecy;
                [UIViewController ig_pushViewController:addVc animated:YES];
            }
//            else
//            {
//                [self presentMessageTips:NSLocalizedString(@"Sorry, only collected works can be added to your album.", nil)];
//            }
        }];
        
        [alertVC addAction:action1];
        [alertVC addAction:action2];
    }
    [UIViewController ig_presentViewController:alertVC animated:YES completion:nil];
}

#pragma mark - Delegate

#pragma mark - SDPhotoBrowserDelegate

- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
{
    return [NSURL URLWithString:_model.worksImageWM];
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
    XQPhotoCell *cell = [self.table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    return cell.imageV.image;
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CGFloat x = cell.separatorInset.left;
    UIFont *font = [UIFont systemFontOfSize:14];
    __weak typeof(self) weakSelf = self;
    if (indexPath.section == 0)
    {
        XQPhotoCell *photoCell = [tableView dequeueReusableCellWithIdentifier:@"XQPhotoCell" forIndexPath:indexPath];
        photoCell.imgUrl = _model.worksImage;
        if ([_model.ifWordPush isEqualToString:@"1"])
        {
            photoCell.isT = YES;
        } else {
            if ([[IGUser getUid] isEqualToString:_model.worksArtistId])
            {
                photoCell.isT = YES;
            } else {
                photoCell.isT = NO;
            }
        }
        //        photoCell.isT = [_model.ifWordPush isEqualToString:@"0"] ? NO : YES;
        photoCell.isGif = [_model.ifGif isEqualToString:@"0"] ? NO : YES;
        if (![_model.worksPlates isEqualToString:@"3"])
        {
            photoCell.plates = _model.worksPlates;
        } else {
            photoCell.plates = ([_model.worksImageWidth floatValue] >= [_model.worksImageHeight floatValue]) ? @"1" : @"2";
        }
        
        photoCell.block = ^{
            IGArtWorkModel *model = [IGArtWorkModel new];
            model.aId = weakSelf.model.worksId;
            model.title = weakSelf.model.worksName;
            model.uploader = weakSelf.model.worksAthena;
            model.image = weakSelf.model.worksImage;
            model.plates = weakSelf.model.plates;
            model.imageWidth = weakSelf.model.worksImageWidth;
            model.imageHeight = weakSelf.model.worksImageHeight;
            AddWordVC *addWordVC = [[AddWordVC alloc] init];
            addWordVC.recommend = model;
            [UIViewController ig_pushViewController:addWordVC animated:YES];
        };
        return photoCell;
    } else if(indexPath.section == 1){
        IGPaintingDetailOperateCell *cell = [[IGPaintingDetailOperateCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell123"];
        cell.model = _model;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.followBtn addTarget:self action:@selector(cellBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell.addToPaintingListBtn setTapActionWithBlock:^{
            IGAddToDrawVC *addVc=[[IGAddToDrawVC alloc]init];
            addVc.workIds=@[weakSelf.model.worksId];
            [UIViewController ig_pushViewController:addVc animated:YES];
        }];
        [cell.voicePlayBtn addTarget:self action:@selector(cellBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell.commentBtn setTapActionWithBlock:^{
            IGCommentVC *commentVC = [[IGCommentVC alloc] initWithType:IGCommentPageTypeZuopin baseModel:weakSelf.model];
            [UIViewController ig_pushViewController:commentVC animated:YES];
        }];
        return cell;
    }
    else if (indexPath.section==2)
    {
        CGFloat heght;
        
        UIButton *pushL = [UIButton buttonWithType:UIButtonTypeCustom];
        pushL.titleLabel.font = [UIFont font14];
        [pushL setTitleColor:[UIColor c5Color] forState:UIControlStateNormal];
        [pushL setTitleColor:[UIColor c5Color] forState:UIControlStateHighlighted];
        NSString *str;
        if ([_model.worksSecrecy isEqualToString:@"2"])
        {
            str = @"";
        }
        else
        {
            switch ([_model.examine integerValue]) {
                case 1:
                    //                str = [NSString stringWithFormat:@"%@人推送", _model.worksPushNum.length > 0?_model.worksPushNum:@"0"];
                    str = [NSString stringWithFormat:@"%@ %@", _model.worksPushNum.length > 0?_model.worksPushNum:@"0",NSLocalizedString(@"Pushes", nil)];
                    break;
                case 2:
                    //                str = [[IGUser getUid] isEqualToString:_model.worksArtistId] ? @"待认证" : @"";
                    str = [[IGUser getUid] isEqualToString:_model.worksArtistId] ? NSLocalizedString(@"To be Verified", nil) : @"";
                    break;
                case 4:
                    [pushL setImage:[UIImage imageNamed:@"badge拷贝2"] forState:UIControlStateNormal];
                    [pushL setImage:[UIImage imageNamed:@"badge拷贝2"] forState:UIControlStateHighlighted];
                    //                str = [[IGUser getUid] isEqualToString:_model.worksArtistId] ? @" 审核未通过" : @"";
                    str = [[IGUser getUid] isEqualToString:_model.worksArtistId] ? NSLocalizedString(@"Examination Failed", nil) : @"";
                    break;
                default:
                    break;
            }
        }
        [pushL setTitle:str forState:UIControlStateNormal];
        [pushL setTitle:str forState:UIControlStateHighlighted];
        [pushL sizeToFit];
        pushL.width += 20;
        //        pushL.height += 10;
        pushL.right = KSCREENWIDTH - x;
        pushL.top = 15;
        [pushL addTarget:self action:@selector(editBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:pushL];
        //作品名
        UILabel *pictureName = [[UILabel alloc] initWithFrame:CGRectMake(x, 15, 0, 0)];
        pictureName.text = _model.worksName;
        pictureName.font = [UIFont boldSystemFontOfSize:20];
        pictureName.textColor = [UIColor c4Color];
        [pictureName sizeToFit];
        [cell.contentView addSubview:pictureName];
        pictureName.width = pushL.left - 5 - pictureName.left;
        pictureName.numberOfLines = 0;
        CGSize si = [Tool getLabelSizeWithText:pictureName.text AndWidth:pictureName.width AndFont:pictureName.font attribute:nil];
        pictureName.height = si.height;
        //作者
        UIButton *auth = [UIButton buttonWithType:UIButtonTypeCustom];
        auth.frame = CGRectMake(x, _model.worksAthena.length > 0 ? pictureName.bottom + 10 : pictureName.bottom, 0, 0);
        [auth setTitle:_model.worksAthena forState:UIControlStateNormal];
        [auth setTitle:_model.worksAthena forState:UIControlStateHighlighted];
        auth.titleLabel.font = font;
        [auth setTitleColor:[UIColor appColor] forState:UIControlStateNormal];
        [auth setTitleColor:[UIColor appColor] forState:UIControlStateHighlighted];
        [auth addTarget:self action:@selector(authorBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:auth];
        if (_model.worksAthena.length)
        {
            [auth sizeToFit];
        }
        //        auth.backgroundColor = [UIColor orangeColor];
        //年代 分类
        //        NSArray *arr = @[_model.worksYears.length > 0?_model.worksYears:@"", _model.worksTypeContent.length > 0?_model.worksTypeContent:@"", _model.worksCollections.length > 0?[NSString stringWithFormat:@"收藏于%@",_model.worksCollections]:@""];
        NSArray *arr = @[_model.worksYears.length > 0?_model.worksYears:@"", _model.worksTypeContent.length > 0?_model.worksTypeContent:@"", _model.worksCollections.length > 0?[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"Collected in", nil),_model.worksCollections]:@""];
        UILabel *time = [[UILabel alloc] initWithFrame:CGRectMake(x,(_model.worksYears.length > 0 ||_model.worksTypeContent.length > 0 || _model.worksCollections.length > 0) ? auth.bottom + 5 : auth.bottom, 0, 0)];
        time.text = [arr componentsJoinedByString:@"  "];
        time.textColor = [UIColor c5Color];
        time.font = font;
        if ((_model.worksYears.length > 0 ||_model.worksTypeContent.length > 0 || _model.worksCollections.length > 0))
        {
            [time sizeToFit];
        }
        [cell.contentView addSubview:time];
        //简介
        NSString *text = _model.worksContent;
        UILabel *context = [[UILabel alloc] initWithFrame:CGRectMake(x, text.length ? time.bottom + 15 : time.bottom, KSCREENWIDTH-x*2, 0)];
        context.numberOfLines = 0;
        context.text = text;
        context.textColor = [UIColor c4Color];
        context.font = font;
        [cell.contentView addSubview:context];
        
        //        NSAttributedString *arrrStr = [[NSAttributedString alloc] initWithData:[text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        //        context.attributedText = arrrStr;
        [context sizeToFit];
        CGSize size = [Tool getLabelSizeWithText:text AndWidth:context.width AndFont:font attribute:nil];
        context.height = size.height;
        heght = context.bottom + 15;
        //标签
        if (_model.worksLabels.count)
        {
            NSArray *biaoQian = [NSArray arrayWithArray:_model.worksLabels];
            CGFloat bQX = x;
            CGFloat bQY = context.bottom + 15;
            NSString *pStr1=[biaoQian objectAtIndex:0];
            
            if (pStr1.length > 0)
            {
                for (int i=0; i<biaoQian.count; i++)
                {
                    if(biaoQian[i] && ![biaoQian[i] isEqualToString:@""])
                    {
                        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(bQX, bQY, 0, 0)];
                        label.textAlignment = NSTextAlignmentCenter;
                        label.font = [UIFont systemFontOfSize:14];
                        label.textColor = [UIColor c4Color];
                        label.text = biaoQian[i];
                        label.backgroundColor = [UIColor c6Color];
                        [cell.contentView addSubview:label];
                        [label sizeToFit];
                        label.width+=28;
                        label.height+=10;
                        label.layer.cornerRadius = label.height / 2;
                        label.layer.masksToBounds = YES;
                        if (label.right>(KSCREENWIDTH-x))
                        {
                            label.x = x;
                            label.y = label.bottom + 13;
                        }
                        bQX = label.right+15;
                        bQY = label.y;
                        heght = label.bottom + 15;
                        label.userInteractionEnabled = YES;
                        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickBiaoQian:)];
                        [label addGestureRecognizer:tap];
                    }
                }
            }
        }
        if (contextHeight != heght)
        {
            contextHeight = heght;
            [tableView reloadData];
        }
    }
    else if (indexPath.section==3)
    {
        // 购买信息  --  收藏--真品
        if (indexPath.row==0)
        {
//            cell.textLabel.textColor = [UIColor c4Color];
////            cell.textLabel.text = [@"￥" stringByAppendingString:_model.worksCollectPrice.length>0?_model.worksCollectPrice:@"0"];
//            cell.textLabel.text = [@"￥" stringByAppendingString:_model.worksCollectPrice.length>0?_model.worksCollectPrice:@"0"];
//            cell.textLabel.hidden =NO;
            
            cell.textLabel.hidden = YES;
            UILabel *moneyLabel = [[UILabel alloc]init];
            moneyLabel.frame = CGRectMake(20, 0, KSCREENWIDTH - 260, cell.size.height);
            moneyLabel.centerY = cell.contentView.centerY;
            moneyLabel.textColor = [UIColor c4Color];
            moneyLabel.text = [@"￥" stringByAppendingString:_model.worksCollectPrice.length>0?_model.worksCollectPrice:@"0"];
//            moneyLabel.backgroundColor = [UIColor yellowColor];
            [cell.contentView addSubview:moneyLabel];
            
            UIButton *xianliang = [UIButton buttonWithType:UIButtonTypeCustom];
            xianliang.frame = CGRectMake(0, 10, 110, 30);
            xianliang.titleLabel.font = [UIFont systemFontOfSize:14];
            [xianliang setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
            xianliang.backgroundColor = [UIColor clearColor];
            xianliang.layer.borderColor = [UIColor c4Color].CGColor;
            xianliang.layer.borderWidth = .5;
            xianliang.titleLabel.textAlignment = NSTextAlignmentCenter;
            //            [xianliang setTitle:@"限量收藏" forState:UIControlStateNormal];
            [xianliang setTitle:NSLocalizedString(@"Limited Collect", nil) forState:UIControlStateNormal];
            if (_model.ifCollected.integerValue == 1)
            {
                //                [xianliang setTitle:@"已收藏" forState:UIControlStateNormal];
                [xianliang setTitle:NSLocalizedString(@"Collected", nil) forState:UIControlStateNormal];
            }
            else if (_model.ifCollected.integerValue == 2)
            {
                //                [xianliang setTitle:@"待支付" forState:UIControlStateNormal];
                [xianliang setTitle:NSLocalizedString(@"Unpaid", nil) forState:UIControlStateNormal];
            }
            
            [xianliang addTarget:self action:@selector(xianliangAction:) forControlEvents:UIControlEventTouchUpInside];
            xianliang.layer.masksToBounds = YES;
            xianliang.layer.cornerRadius = 15;
            [cell.contentView addSubview:xianliang];
            xianliang.right = KSCREENWIDTH - x;
            
            UILabel *msg = [[UILabel alloc] initWithFrame:CGRectZero];
            msg.font = [UIFont systemFontOfSize:14];
            msg.textColor = [UIColor c5Color];
            //            msg.text = [NSString stringWithFormat:@"%@人收藏/%@", _model.worksCollectNumHas.length>0?_model.worksCollectNumHas:@"0", [_model.worksCollectNumLimited integerValue] < 1?@"无限制":_model.worksCollectNumLimited];
            msg.text = [NSString stringWithFormat:@"%@ %@/%@", _model.worksCollectNumHas.length>0?_model.worksCollectNumHas:@"0", NSLocalizedString(@"Collects", nil),[_model.worksCollectNumLimited integerValue] < 1?NSLocalizedString(@"No Limit", nil):_model.worksCollectNumLimited];
            [cell.contentView addSubview:msg];
            [msg sizeToFit];
            msg.center = xianliang.center;
            msg.right = xianliang.left - 10;
        }
        else if (indexPath.row==1)
        {
            if ([_model.worksRealIf integerValue] == 1)
            {
                cell.textLabel.textColor = [UIColor c4Color];
                cell.textLabel.text = [@"￥" stringByAppendingString:_model.worksRealPrice.length>0?_model.worksRealPrice:@"0"];
                //              cell.textLabel.hidden = [detailsInfo.price_open isEqualToString:@"2"];
                UIButton *buy = [UIButton buttonWithType:UIButtonTypeCustom];
                buy.frame = CGRectMake(0, 10, 90, 30);
                buy.titleLabel.font = [UIFont systemFontOfSize:14];
                [buy setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
                //                [buy setTitle:@"真品购买" forState:UIControlStateNormal];
                [buy setTitle:NSLocalizedString(@"Authenticated Works Purchasing", nil) forState:UIControlStateNormal];
                [buy addTarget:self action:@selector(buyAction:) forControlEvents:UIControlEventTouchUpInside];
                buy.layer.masksToBounds = YES;
                buy.layer.cornerRadius = 15;
                buy.layer.borderColor = [UIColor c4Color].CGColor;
                buy.layer.borderWidth = .5;
                [cell.contentView addSubview:buy];
                buy.right = KSCREENWIDTH - x;
                
                UILabel *msg = [[UILabel alloc] initWithFrame:CGRectZero];
                msg.font = [UIFont systemFontOfSize:14];
                msg.textColor = [UIColor c5Color];
                //                msg.text = [NSString stringWithFormat:@"%@件", _model.worksRealNum.length>0?_model.worksRealNum:@"0"];
                msg.text = [NSString stringWithFormat:@"%@ %@", _model.worksRealNum.length>0?_model.worksRealNum:@"0",NSLocalizedString(@"Pieces", nil)];
                [cell.contentView addSubview:msg];
                [msg sizeToFit];
                msg.center = buy.center;
                msg.right = buy.left - 10;
                
                UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(x, 0, KSCREENWIDTH-x-x, .5)];
                line.backgroundColor = [UIColor c6Color];
                [cell.contentView addSubview:line];
            }
        }
    }
    else if (indexPath.section==4)
    {
        // 作者信息
        cell.clipsToBounds = YES;
        CGFloat iconWidth = 40;
        UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(x, (70 - iconWidth) / 2, iconWidth, iconWidth)];
        icon.layer.cornerRadius = iconWidth / 2;
        icon.layer.masksToBounds = YES;
        icon.backgroundColor = [UIColor c2Color];
        [icon sd_setImageWithURL:[NSURL URLWithString:_model.artistImage]];
        icon.contentMode=UIViewContentModeScaleAspectFill;
        [cell.contentView addSubview:icon];
        
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectZero];
        name.font = [UIFont font16];
        name.text = _model.worksArtist;
        name.textColor = [UIColor c4Color];
        [cell.contentView addSubview:name];
        [name sizeToFit];
        name.top = icon.top;
        name.x = icon.right + 15;
        
        UILabel *zuoPin = [[UILabel alloc] initWithFrame:CGRectZero];
        zuoPin.font = [UIFont systemFontOfSize:14];
        //        zuoPin.text = [NSString stringWithFormat:@"作品 %@",_model.artistNum?:@"0"];
        zuoPin.text = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"Artworks", nil),_model.artistNum?:@"0"];
        zuoPin.textColor = [UIColor c5Color];
        [cell.contentView addSubview:zuoPin];
        [zuoPin sizeToFit];
        zuoPin.x = icon.right + 15;
        zuoPin.top = name.bottom + 5;
        
        UILabel *fans = [[UILabel alloc] initWithFrame:CGRectZero];
        fans.font = [UIFont systemFontOfSize:14];
        //        fans.text = [NSString stringWithFormat:@"粉丝 %@",_model.artistCollectionNum?:@"0"];
        fans.text = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"Fans",nil),_model.artistCollectionNum?:@"0"];
        fans.textColor = [UIColor grayColor];
        [cell.contentView addSubview:fans];
        [fans sizeToFit];
        fans.x = zuoPin.right + 15;
        fans.top = name.bottom + 5;
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else if (indexPath.section==5)
    {
        //  @"猜您喜欢";
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectZero];
        //        title.text = @"猜您喜欢";
        title.text = NSLocalizedString(@"Recommended", nil);
        title.font = font;
        [cell.contentView addSubview:title];
        [title sizeToFit];
        title.x = x;
        title.y = 15;
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake((KSCREENWIDTH-40)/4, (KSCREENWIDTH-40)/4);
        layout.minimumLineSpacing = 2;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        UICollectionView *collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, title.bottom, KSCREENWIDTH, (KSCREENWIDTH-40)/4+20) collectionViewLayout:layout];
        collect.delegate = self;
        collect.dataSource = self;
        collect.backgroundColor = [UIColor whiteColor];
        [collect registerClass:[ArtGalleryCell_third class] forCellWithReuseIdentifier:@"collect"];
        [cell.contentView addSubview:collect];
        inset = x;
        [collect reloadData];
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0)
    {
        [self.view endEditing:YES];
        if ([_model.ifGif isEqualToString:@"0"])
        {
            XQPhotoCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            
            //点击事件
            ImageZoomView *img=[[ImageZoomView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT) andWithImage:_model.worksImageWM type:_model.worksPlates scale:[_model.worksImageWidth floatValue]/[_model.worksImageHeight floatValue] placeholderImage:cell.imageV.image];
            [kKeyWindow addSubview:img];
        }
        else if ([_model.ifGif isEqualToString:@"1"])
        {
            YHBrowserImageView *gifV = [[YHBrowserImageView alloc]initWithFrame:CGRectMake(KSCREENWIDTH*0, 0,KSCREENWIDTH , KSCREENHEIGHT)];
            //            @"http://ww2.sinaimg.cn/bmiddle/642beb18gw1ep3629gfm0g206o050b2a.gif"
            [gifV setImageWithURL:[NSURL URLWithString:_model.worksImageWM] placeholderImage:nil];
            [kKeyWindow addSubview:gifV];
        }
    }
    if (indexPath.section == 4)
    {
        IntroViewController *vc = [[IntroViewController alloc] init];
        vc.u_id = _model.worksArtistId;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_model.worksId)
    {
        return 6;
    }
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0)
    {
        return 1;
    }
    else if (section==1)
    {
        return 1;
    }
    else if (section==2)
    {
        return 1;
    }
    else if (section==3)
    {
        return 2;
    }
    else if (section==4)
    {
        return 1;
    }
    else if(section == 5){
        return 1;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if ([_model.worksPlates integerValue]==1)
        {
            //横板
            return KSCREENWIDTH*1080/1920;
            //            return 211;
        }
        else if ([_model.worksPlates  integerValue]==2)
        {
            //坚板
            return KSCREENWIDTH / 2 * 16 / 9;
        }
        //批量上传
        else if ([_model.worksPlates  integerValue] == 3)
        {
            if ([_model.worksImageWidth floatValue] >= [_model.worksImageHeight floatValue])
            {
                //横板
                return KSCREENWIDTH*1080/1920;
            }
            else if ([_model.worksImageWidth floatValue] < [_model.worksImageHeight floatValue])
            {
                //坚板
                return KSCREENWIDTH / 2 * 16 / 9;
            }
            
        }
    } else if(indexPath.section == 1){
        return 50;
    }
    else if (indexPath.section == 2)
    {
        return contextHeight;
    }
    else if (indexPath.section == 3)
    {
        if (indexPath.row == 0)
        {
            return 60;
        }
        else if (indexPath.row == 1 && [_model.worksRealIf integerValue] == 1)
        {
            return 60;
        }
        return 0;
    }
    else if (indexPath.section==4)
    {
        return 70;
    }
    else if (indexPath.section==5)
    {
        CGFloat h;
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectZero];
        //        title.text = @"猜您喜欢";
        title.text = NSLocalizedString(@"Recommended", nil);
        title.font = [UIFont systemFontOfSize:15];
        [title sizeToFit];
        h=title.height+15;
        
        h += ((KSCREENWIDTH-40)/4+20);
        
        return h;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==3)
    {
        return .5f;
    }
    else if (section==4)
    {
        return 10;
    }
    else if (section==5)
    {
        return 10;
    }
    return .01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return .01f;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    if (scrollView==self.table)
    {
        [self.view endEditing:YES];
    }
}

#pragma mark — UICollectionViewDelegateFlowLayout, UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //    return _model.guessYourLikeList.count?:0;
    return _recListArray.count?:0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ArtGalleryCell_third *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collect" forIndexPath:indexPath];
    //    NSArray *arr = _model.guessYourLikeList;
    //    cell.imgUrl = arr[indexPath.item][@"image"];
    IGWorkDetailSigleRecModel *model = _recListArray[indexPath.item];
    cell.imgUrl = model.image;
    //    cell.imgUrl = _recListArray[indexPath.item][@"image"];
    cell.isTreasure = NO;
    cell.isGus = YES;
    [cell setNeedsLayout];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.view endEditing:YES];
    //    NSArray *arr = _model.guessYourLikeList;
    XiangQingViewController *vc = [[XiangQingViewController alloc] init];
    //    vc.p_id = arr[indexPath.item][@"id"];
    IGWorkDetailSigleRecModel *model = _recListArray[indexPath.item];
    vc.p_id = model.pid;
    //    vc.p_id = _recListArray[indexPath.item][@"id"];
    vc.isRoot = YES;
    [UIViewController ig_pushViewController:vc animated:YES];
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, inset, 0, inset);
}

#pragma mark - private events

- (void)ig_rightButtonPressed:(id)sender
{
    //公开作品
    if ([_model.worksSecrecy isEqualToString:@"1"])
    {
        //如果审核通过
        if ([_model.examine isEqualToString:@"1"] || [_model.examine isEqualToString:@"3"])
        {
            @KWeakObj(self)
            YXScrollowActionSheet *sheet = [[YXScrollowActionSheet alloc] init];
            NSArray *contnetArr = @[];
            NSArray *blockArr = @[];
            //如果是自己的作品
            if ([_model.worksArtistId isEqualToString:[IGUser getUid]])
            {
                contnetArr = @[NSLocalizedString(@"Edit", nil), NSLocalizedString(@"Add to My Album", nil)];
                
                blockArr = @[^(){
                    PhotoEditVC *vc = [[PhotoEditVC alloc] initWithNibName:@"PhotoEditVC" bundle:nil];
                    vc.price = selfWeak.model.worksCollectPrice;
                    vc.kuc = selfWeak.model.worksCollectNumLimited;
                    vc.worksId = selfWeak.model.worksId;
                    vc.block = ^(NSString *price, NSString *kuc) {
                        selfWeak.model.worksCollectPrice = price;
                        selfWeak.model.worksCollectNumLimited = kuc;
                        [selfWeak.table reloadData];
                    };
                    [UIViewController ig_pushViewController:vc animated:YES];
                }, ^(){
                    if ([[IGUser getUid] isEqualToString:selfWeak.model.worksArtistId])
                    {
                        IGAddToDrawVC *addVc=[[IGAddToDrawVC alloc]init];
                        addVc.workIds=@[selfWeak.model.worksId];
                        [UIViewController ig_pushViewController:addVc animated:YES];
                    }
//                    else
//                    {
//                        [self presentMessageTips:NSLocalizedString(@"Sorry, only collected works can be added to your album.", nil)];
//                    }
                    
                },^(){
                    
                }];
            }
            //如果不是自己的作品
            else
            {
                contnetArr = @[ NSLocalizedString(@"Add to My Album", nil),];
                blockArr = @[^(){
//                    if (_model.ifCollected.integerValue == 1)
//                    {
                        IGAddToDrawVC *addVc=[[IGAddToDrawVC alloc]init];
                        addVc.workIds=@[selfWeak.model.worksId];
                        [UIViewController ig_pushViewController:addVc animated:YES];
//                    }
//                    else
//                    {
//                        [self presentMessageTips:NSLocalizedString(@"Sorry, only collected works can be added to your album.", nil)];
//                    }
                    
                },^(){
                    
                }];
                
            }
            IGShareModel *shareModel = [_model getShareModel];
            sheet.shareModel = shareModel;
            [sheet showWithContentArray:contnetArr blockArr:blockArr];
        }
        //审核中或者审核不通过
        else
        {
            [self showAlertViewWithTag:101];
        }
    }
    //私密作品
    else if (([_model.worksSecrecy isEqualToString:@"2"]))
    {
        [self showAlertViewWithTag:101];
    }
}

- (void)editBtnClick
{
    if ([[IGUser getUid] isEqualToString:_model.worksArtistId])
    {
        if ([_model.examine isEqualToString:@"2"])
        {
            [self presentMessageTips:NSLocalizedString(@"Under Verification", nil)];
        }
        else if ([_model.examine isEqualToString:@"4"])
        {
            [self showAlertViewWithTag:100];
        }
    }
}

-(void)cellBtnClicked:(UIButton *)cellBtn{
    NSLog(@"%zd",cellBtn.tag);
    if (cellBtn.tag == 101) {//关注
        //已关注过得话，点击取消关注
        __weak typeof(self) weakSelf = self;
        //修改数据源  然后刷新tableView就可以了
        if ([_model.ifLove isEqualToString:@"1"]) {
            
            self.cancelFavoriteApi = [[IGWorkDetailCancelFavoriteApi alloc]init];
            self.cancelFavoriteApi.type = @"1";
            self.cancelFavoriteApi.thingId = _model.worksId;
            [self.cancelFavoriteApi startWithDecodeClass:[IGWorkDetailCancelFavoriteResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                if (responseObject) {
                    IGWorkDetailCancelFavoriteResp *response = responseObject;
                    IGBaseRespHead *header = response.resHeader;
                    NSString *code = header.code;
                    if ([code isEqualToString:@"success"]) {
                        weakSelf.model.ifLove = @"0";
                        if ([weakSelf.model.loveNum integerValue] < 1) {
                            weakSelf.model.loveNum = @"0";
                        } else weakSelf.model.loveNum = [NSString stringWithFormat:@"%ld",(long)([weakSelf.model.loveNum integerValue] - 1)];
                        [weakSelf.table reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
                    }
                }
            }];
        } else {
            self.favoriteApi = [IGWorkDetailFavoriteApi new];
            self.favoriteApi.type = @"1";
            self.favoriteApi.thingId = _model.worksId;
            [self.favoriteApi startWithDecodeClass:[IGWorkDetailFavoriteResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                if (responseObject) {
                    IGWorkDetailFavoriteResp *response = responseObject;
                    IGBaseRespHead *header = response.resHeader;
                    NSString *code = header.code;
                    if ([code isEqualToString:@"success"]) {
                        weakSelf.model.ifLove = @"1";
                        weakSelf.model.loveNum = [NSString stringWithFormat:@"%ld",(long)([weakSelf.model.loveNum integerValue] + 1)];
                        [weakSelf.table reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
                    }
                }
            }];
        }
    } else if (cellBtn.tag == 102){//添加画单
        //跳转画单添加界面 带id
        IGAddToDrawVC *addDrawVC = [[IGAddToDrawVC alloc]init];
        addDrawVC.workIds = @[_model.worksId];
        addDrawVC.isSecrecy = _model.worksSecrecy;
        [UIViewController ig_pushViewController:addDrawVC animated:YES];
    } else if (cellBtn.tag == 103){//音视频播放
        //本界面播放  还是跳转界面播放
    } else if (cellBtn.tag == 104){//评论
        //跳转评论列表界面 带id  回来要刷新评论数
    }
}

#pragma mark - 点击作者, 标签进入搜索界面
/*
 需要判断  1.如果作者和下面的发布者名称一致，则点击跳转发布者界面
 2.如果作者和下面的发布者名称不一致--当前界面做搜索请求----如果是认证艺术家之类的，跳艺术家个人主页
 |
 |----如果是非认证的或者普通用户的话  跳转到搜索界面的，并定位到用户界面
 */
- (void)authorBtnClick:(UIButton *)btn
{
    NSString *str = btn.titleLabel.text;
    if ([str isEqualToString:_model.worksArtist]) {
        IntroViewController *vc = [[IntroViewController alloc] init];
        vc.u_id = _model.worksArtistId;
        [UIViewController ig_pushViewController:vc animated:YES];
    } else{
        _searchApi = [[IGMainSearchApi alloc]init];
        _searchApi.searchKey = str;
        _searchApi.type = IGSearchTypeUser;
        _searchApi.page = 1;
        [_searchApi startWithDecodeClass:[IGMainSearchResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
            NSLog(@"%@",responseObject);
            IGMainSearchResp *response = responseObject;
            IGMainSearchModel *model = response.data;
            if (model.lstUser.count) {
                IGUserInfo *userInfo = model.lstUser[0];
                NSString *uid = userInfo.uid;
                IntroViewController *vc = [[IntroViewController alloc] init];
                vc.u_id = uid;
                [UIViewController ig_pushViewController:vc animated:YES];
                return;
            }
        }];
        IGSearchVC *searchVC = [[IGSearchVC alloc] initWithSearchKey:str];
        [UIViewController ig_pushViewController:searchVC animated:YES];
    }
    
}

- (void)clickBiaoQian:(UITapGestureRecognizer *)tap
{
    if ([tap.view isKindOfClass:[UILabel class]])
    {
        UILabel *label = (UILabel *)tap.view;
        NSString *str = label.text;
        IGSearchVC *searchVC = [[IGSearchVC alloc] initWithSearchKey:str];
        [UIViewController ig_pushViewController:searchVC animated:YES];
    }
}

#pragma mark ===== 推送至画屏
- (void)pushPhoto:(UIButton *)btn
{
    self.igalleryListApi = [[IGiGalleryListApi alloc] initWithType:IGiGalleryListTypeSuccess];
    __weak typeof(self) weakSelf = self;
    [self.igalleryListApi startWithDecodeClass:[IGiGalleryListResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            IGiGalleryListResp *resp = responseObject;
            IGiGalleryListModel *model = resp.data;
            weakSelf.iGalleryListArr = [NSArray arrayWithArray:model.equs];
            
            if (weakSelf.iGalleryListArr.count == 0)
            {
                findView = [NotFindDeviceView showNotFindDeviceView];
                findView.bangdingBlock = ^{
                    [UIViewController ig_pushViewControllerClass:[IGMyiGalleryVC class] animated:YES];
                };
            }
            else if (weakSelf.iGalleryListArr.count == 1)
            {
                [weakSelf pushToDev];
            }
            else
            {
                IGArtWorkModel *model = [IGArtWorkModel new];
                model.aId = _model.worksId;
                model.title = _model.worksName;
                model.uploader = _model.worksAthena;
                model.image = _model.worksImage;
                IGPushiGalleryListVC *listVC = [[IGPushiGalleryListVC alloc] initWithType:IGPushiGalleryType1N];
                listVC.recommend = model;
                [UIViewController ig_pushViewController:listVC animated:YES];
            }
        }
    }];
}


- (void)pushToDev
{
    [self presentMessageTips:NSLocalizedString(@"Pushing...", nil)];
    IGiGalleryEqu *equ = self.iGalleryListArr[0];
    IGiGalleryPushApi *pushApi = [[IGiGalleryPushApi alloc] initWithMacIds:@[equ.macId] pIds:@[_p_id]];
    //    [self presentMessageTips:@"正在推送..."];
    
    [pushApi startWithDecodeClass:[IGiGalleryPushResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            //            [self presentMessageTips:@"推送成功..."];
            [self presentMessageTips:NSLocalizedString(@"Pushed Successfully...\n Would show up until device online.", nil)];
        }
    }];
}

#pragma mark ==== 限量收藏
- (void)xianliangAction:(UIButton *)btn
{
    @KWeakObj(self)
    [self.view endEditing:YES];
    if ([_model.worksArtistId isEqualToString:[IGUser getUid]])
    {
        //        [self presentMessageTips:@"您不能收藏自己的作品"];
        [self presentMessageTips:NSLocalizedString(@"Can't Collect Your Own Works", nil)];
        return;
    }
    
    //1:已收藏；0未收藏, 2:待收藏
    if (_model.ifCollected.integerValue == 1)
    {
        //        [self presentMessageTips:@"已收藏"];
        [self presentMessageTips:NSLocalizedString(@"Collected", nil)];
        return;
    }
    else if (_model.ifCollected.integerValue == 2)
    {
        [UIViewController ig_pushViewControllerClass:[MyOrdersViewController class] animated:YES];
        return;
    }
    
    IGAddOrderApi *api = [IGAddOrderApi new];
    api.worksId = _p_id;
    [api startWithDecodeClass:[IGAddOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject)
        {
            IGAddOrderResp *resp = responseObject;
            IGAddOrderModel *model = resp.data;
            if ([model.method isEqualToString:@"paySuccess"])
            {
                //                价格为0  直接支付成功
                //                [selfWeak presentMessageTips:NSLocalizedString(@"Collection success", nil)];
                [selfWeak loadData];
            }
            else
            {
                BuyCllowerViewController *vc = [[BuyCllowerViewController alloc] init];
                vc.model = model;
                vc.type = 1;
                [UIViewController ig_pushViewController:vc animated:YES];
            }
        }
    }];
    
    
    
    
}

#pragma mark - 真品购买
- (void)buyAction:(UIButton *)btn
{
    [self.view endEditing:YES];
    @KWeakObj(self)
    if ([_model.worksArtistId isEqualToString:[IGUser getUid]])
    {
        [selfWeak presentMessageTips:NSLocalizedString(@"You can't buy your own goods", nil)];
        return;
    }
    GoodsDetailVC *vc = [[GoodsDetailVC alloc] init];
    vc.goodsId = _model.goodsId;
    [UIViewController ig_pushViewController:vc animated:YES];
}

#pragma mark - UIScrollView Category
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
    IGEmptyView *emptyView = [[IGEmptyView alloc] init];
    //    emptyView.title = @"暂无数据~";
    emptyView.title = NSLocalizedString(@"No Data", nil);
    emptyView.requestApi = _api;
    return emptyView;
}

- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
